package edu.nf.vrs.app.controller;

import edu.nf.vrs.announcement.dto.AnnouncementDTO;
import edu.nf.vrs.announcement.dto.AnnouncementPageDTO;
import edu.nf.vrs.announcement.inf.AnnouncementService;
import edu.nf.vrs.app.vo.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author: @Wai
 * Date: 2022-4-22
 */
@Tag(name ="AnnouncementController", description = "公告服务接口")
@RestController
@RequestMapping("/api/v1")
public class AnnouncementController extends BaseController {

    @DubboReference(interfaceClass = AnnouncementService.class, version="1.0.0",check = false)
    private AnnouncementService service;

    @GetMapping("/announcement/list")
    @Operation(summary="查询公告列表", method = "GET")
    @Parameters({
            @Parameter(name="page", description="页码", required=true, in = ParameterIn.QUERY),
            @Parameter(name="limit", description="每页显示记录数", required=true, in = ParameterIn.QUERY)
    })
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "返回公告列表集合"),
            @ApiResponse(responseCode = "500", description = "服务异常", content = @Content)
    })
    public ResultVO<List<AnnouncementDTO>> listAnnouncement(int page, int limit) {
        AnnouncementPageDTO pageDTO = service.listAnnouncement(page, limit);
        return pageResult(pageDTO.getTotal(), pageDTO.getList());
    }

    @GetMapping("/announcement/{id}")
    @Operation(summary="根据ID查看公告信息", method = "GET")
    @Parameter(name="id", description="公告ID", required=true, in = ParameterIn.PATH)
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "返回公告信息"),
            @ApiResponse(responseCode = "500", description = "服务异常", content = @Content)
    })
    public ResultVO<AnnouncementDTO> getAnnouncement(@PathVariable("id") int id) {
        AnnouncementDTO dto = service.getAnnouncementById(id);
        return success(dto);
    }
}
